package com.bcn.login_mybatisplus_demo.storage.controller;

import java.util.List;

import com.bcn.login_mybatisplus_demo.common.controller.BaseController;
import com.bcn.login_mybatisplus_demo.common.page.TableDataInfo;
import com.bcn.login_mybatisplus_demo.pojo.vo.R;
import com.bcn.login_mybatisplus_demo.storage.domain.TAppStorage;
import com.bcn.login_mybatisplus_demo.storage.service.ITAppStorageService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

/**
 * 收纳区域Controller
 * 
 * @author administrator
 * @date 2025-03-13
 */
@RestController
@RequestMapping("/system/storage")
public class TAppStorageController extends BaseController
{
    private String prefix = "system/storage";

    @Autowired
    private ITAppStorageService tAppStorageService;

    @GetMapping()
    public String storage()
    {
        return prefix + "/storage";
    }

    /**
     * 查询收纳区域列表
     */
    @GetMapping("/list")
    public TableDataInfo list(TAppStorage tAppStorage)
    {
        startPage();
        List<TAppStorage> list = tAppStorageService.selectTAppStorageList(tAppStorage);
        return getDataTable(list);
    }

    /**
     * 新增收纳区域
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存收纳区域
     */
    @PostMapping("/add")
    public R addSave(@RequestBody TAppStorage tAppStorage)
    {
        return R.success(tAppStorageService.insertTAppStorage(tAppStorage));
    }

    /**
     * 修改收纳区域
     */
    @GetMapping("/edit/{storageId}")
    public String edit(@PathVariable("storageId") Long storageId, ModelMap mmap)
    {
        TAppStorage tAppStorage = tAppStorageService.selectTAppStorageById(storageId);
        mmap.put("tAppStorage", tAppStorage);
        return prefix + "/edit";
    }

    /**
     * 修改保存收纳区域
     */
    @PostMapping("/edit")
    public R editSave(@RequestBody TAppStorage tAppStorage)
    {
        return R.success(tAppStorageService.updateTAppStorage(tAppStorage));
    }

    /**
     * 删除收纳区域
     */
    @GetMapping( "/remove/{id}")
    public R remove(@PathVariable("id") Integer id)
    {
        return R.success(tAppStorageService.deleteTAppStorageById(id.longValue()));
    }
}
